package com.daoeping.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Password {

	public String setmd5Pass(String str){
		MessageDigest md5 = null;
		try {
			md5 = MessageDigest.getInstance("MD5");
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		md5.update(str.getBytes());
		return this.toHex(md5.digest()).toString();
    }
	public String toHex(byte buffer[]) { 
        StringBuffer sb = new StringBuffer(); 
        String s = null; 
        for (int i = 0; i < buffer.length; i++) { 
            s = Integer.toHexString((int) buffer[i] & 0xff); 
            if (s.length() < 2) { 
                sb.append('0'); 
            } 
            sb.append(s); 
        } 
        return sb.toString(); 
    }
  
} 
